class queue:
    def __init__(self, maxsize):
        self.maxsize = maxsize
        self.queue = [0 for _ in range(maxsize)]
        self.front = -1
        self.rear = -1

    def __str__(self):
        return str(self.queue[self.front : self.rear + 1])

    def is_empty(self):
        if self.front == self.rear:
            return True
        else:
            return False

    def is_full(self):
        if self.rear + 1 == self.maxsize:
            return True
        else:
            return False

    def enqueue(self, data):
        if self.is_full():
            raise Exception("queue is full")

        self.rear += 1
        self.queue[self.rear] = data
        
        if self.front == -1:
            self.front += 1

    def dequeue(self):
        if self.is_empty():
            raise Exception("queue is empty")

        self.front += 1
        return self.queue[self.front]

    def get_front(self):
        if self.is_empty():
            raise Exception("queue is empty")
        return self.queue[self.front]

    def get_rear(self):
        if self.is_empty():
            raise Exception("queue is empty")
        return self.queue[self.rear]


if __name__ == "__main__":
    q = queue(5)
    q.enqueue(1)
    q.enqueue(2)
    q.enqueue(3)
    q.enqueue(4)
    q.enqueue(5)
    try:
        q.enqueue(6)
    except Exception as e:
        print(e)
    print(q)
    print(q.get_front())
    print(q.get_rear())

    # 2.出队列
    q.dequeue()
    print(q)
    print(q.get_front())
    print(q.get_rear())
